home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v10n16.arc / POINT.CPP < prev    next >
Text File  |  1991-08-27  |  2KB  |  96 lines

  1. // POINT.CPP
  2. // Definitions of Member Functions for Point and Pixel Classes
  3. // Copyright (C) 1991 Ziff Davis Communications
  4. // PC Magazine * Ray Duncan
  5.  
  6. #include <math.h>
  7. #include <iostream.h>
  8. #include "point.h"
  9.  
  10. // Member function for POINT class to set X coordinate
  11. void POINT::setX(double NewX)
  12. {
  13.     X = NewX;
  14. };
  15.  
  16. // Member function for POINT class to set Y coordinate
  17. void POINT::setY(double NewY)
  18. {
  19.     Y = NewY;
  20. };
  21.  
  22. // Member function for POINT class to fetch X coordinate
  23. double POINT::getX(void)
  24. {
  25.     return(X);
  26. };
  27.  
  28. // Member function for POINT class to fetch Y coordinate
  29. double POINT::getY(void)
  30. {
  31.     return(Y);
  32. };
  33.  
  34. // Constructor function for POINT class
  35. POINT::POINT (double NewX, double NewY)
  36. {
  37.     X = NewX;
  38.     Y = NewY;
  39. };
  40.  
  41. // member function for POINT class to translate point by given X,Y
  42. void POINT::translate(double DispX, double DispY)
  43. {
  44.     X = X + DispX;
  45.     Y = Y + DispY;      
  46. }
  47.  
  48. // member function for POINT class to rotate point by given degrees
  49. void POINT::rotate(double degrees)
  50. {
  51.     double radians = deg2rad(degrees);
  52.     double tempX = (X * cos(radians)) - (Y * sin(radians));
  53.     Y = (X * sin(radians)) + (Y * cos(radians));
  54.     X = tempX;    
  55. }
  56.  
  57. // private member function for POINT class to convert degrees to radians
  58. double POINT::deg2rad(double degrees)
  59. {
  60.     return ((degrees * 2 * pi)/360);
  61. }
  62.  
  63. // private member function for POINT class to convert radians to degrees
  64. double POINT::rad2deg(double radians)
  65. {
  66.     return ((radians * 360)/(2 * pi));
  67. }
  68.  
  69. // Member function for PIXEL class to set color
  70. void PIXEL::setColor(int NewColor)
  71. {
  72.     Color = NewColor;
  73. };
  74.  
  75. // Member function for PIXEL class to fetch color
  76. int PIXEL::getColor(void)
  77. {
  78.     return(Color);
  79. };
  80.  
  81. // Member function for PIXEL class to display location and color
  82. void PIXEL::display(void)
  83. {
  84.     cout << "  X = " << getX();
  85.     cout << "  Y = " << getY();
  86.     cout << "  Color = " << getColor();
  87. };
  88.  
  89. // Constructor function for PIXEL class
  90. PIXEL::PIXEL (double NewX, double NewY, int NewColor) : POINT (NewX, NewY)
  91. {
  92.     Color = NewColor;
  93. };
  94.  
  95.  
  96.